package cn.bandeqing.frame.dubbo;

import cn.bandeqing.base.util.Constants;
import cn.bandeqing.base.util.SpringContext;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group = {CommonConstants.CONSUMER}, order = -10000)
public class DubboConsumerFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        // 追加 Same-Token 参数

//        RpcContext.getContext().setAttachment(SaSameUtil.SAME_TOKEN, SaSameUtil.getToken());

        RpcContext.getClientAttachment().setAttachment(Constants.appName, SpringContext.appName());

        // 如果有其他自定义附加数据，如租户
//        RpcContext.getContext().setAttachment(Constant.appName, SpringContext.appName());

        // 开始调用
        return invoker.invoke(invocation);
    }

}
